﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JOIN.Rights.Model;
using Kevin.Framework.Data;

namespace JOIN.Rights.BLL
{
    public class AdminBLL:BLLBase<AdminInfo>
    {
        public AdminBLL(AdminInfo admin):base(admin)
        {
 
        }
        public ServiceResult<AdminInfo> Check()
        {

            ServiceResult<AdminInfo> serviceResult = new ServiceResult<AdminInfo>();
            try
            {
                int recordCount = 0;
                List<AdminInfo> list = base.Entity.SelectedByProperties<AdminInfo>(out recordCount, 1, 1);

                serviceResult.Successed = list.Count > 0;

                if (serviceResult.Successed)
                {
                    OnlineUserInfo user = new OnlineUserInfo();
                    user.UserNO = base.Entity.UserNO;
                    user.UserName = base.Entity.UserName;
                    user.LoginTime = DateTime.Now;
                    user.TokenID = Guid.NewGuid().ToString();
                    
                    //user.UserEntity = list[0];
                    user.Insert();
                    serviceResult.Object = list[0];
                    serviceResult.RecordCount = recordCount;
                    serviceResult.List = null;
                }
            }
            catch (Exception ex)
            {
                serviceResult.ErrorMsg = "登录失败:" + ex.Message;
                serviceResult.Successed = false;
                serviceResult.RecordCount = 0;
                serviceResult.List = null;
            }

            return serviceResult;
        }
    }
}
